package com.zb.service.impl;
import com.zb.mapper.ScoreMapper;
import com.zb.entity.Score;
import org.springframework.stereotype.Service;
import com.zb.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.zb.util.PageUtil;
import java.util.ArrayList;
import java.util.HashMap;

@Service
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;

    public Score getScoreById(Long id)throws Exception{
        return scoreMapper.getScoreById(id);
    }

    public List<Score>	getScoreListByMap(Map<String,Object> param)throws Exception{
        return scoreMapper.getScoreListByMap(param);
    }

    public Integer getScoreCountByMap(Map<String,Object> param)throws Exception{
        return scoreMapper.getScoreCountByMap(param);
    }

    public Integer qdtxAddScore(Score score)throws Exception{
            //score.setCreatedTime(new Date());
            return scoreMapper.insertScore(score);
    }

    public Integer qdtxModifyScore(String score,Long userId)throws Exception{
        //score.setUpdatedTime(new Date());
        return scoreMapper.updateScore(score,userId);
    }

    public Integer qdtxDeleteScoreById(Long id)throws Exception{
        return scoreMapper.deleteScoreById(id);
    }

    public PageUtil<Score> queryScorePageByMap(Map<String,Object> param,Integer index,Integer size)throws Exception{
        param.put("start",(index-1)*size);
        param.put("size", size);

        List<Score> scoreList = scoreMapper.getScoreListByMap(param);
        Integer count = scoreMapper.getScoreCountByMap(param);

        PageUtil<Score> page = new PageUtil<Score>();
        page.setData(scoreList);
        page.setIndex(index);
        page.setSize(size);
        page.setCount(count);
        return page;
    }

    public Integer qdtxBatchDeleteScore(String ids)throws Exception{
        Map<String,List<String>> param=new HashMap<String,List<String>>();
        String[] paramArrays=ids.split(",");
        List<String> idList=new ArrayList<String>();
            for (String temp:paramArrays){
                idList.add(temp);
            }
        param.put("ids",idList);
        return scoreMapper.batchDeleteScore(param);
    }


}
